import sys
from PIL import Image
import requests
from io import BytesIO
import pytesseract

pytesseract.pytesseract.tesseract_cmd = '/opt/homebrew/bin/tesseract'

def parse(url: str):
    response = requests.get(url)
    if response.status_code != 200:
        return "Failed to fetch the image"
    else:
        image = Image.open(BytesIO(response.content))
        text = pytesseract.image_to_string(image, lang='chi_sim')
        result = "Processed result: " + text
        return result

if __name__ == '__main__':
    # 检查命令行参数数量
    if len(sys.argv) > 1:
        url = sys.argv[1]
        print(parse(url))  # 调用parse函数并打印结果
    else:
        print("No URL provided")
